import requests
from apicore.SendRequest import sendRequest


class sendApi(sendRequest):
    def order(self, token, *args):
        uri = "/api/front/order/pre/order"
        data = {
            "preOrderType": "buyNow",
            "orderDetails": [
                {
                    "attrValueId": args[0][0],
                    "productId": args[0][1],
                    "productNum": args[0][2]
                }
            ]
        }
        headers = {
            "Content-Type": "application/json",
            "authori-zation": token
        }
        response = self.send_request('POST', uri, header=headers, json=data)
        self.logger.info(f"调用接口 {uri}，请求数据：{data}，请求头：{headers}")
        if response.status_code == 200:
            return response
        else:
            return None
